package com.glela.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.request.RequestUserSign;
import com.glela.platform.model.response.ResponseBaseModel;
import com.glela.platform.model.response.ResponseResultModel;
import com.glela.platform.service.UserSignService;
import com.glela.platform.util.ParameterUtils;

@Controller
@RequestMapping(value = "/userSign")
public class UserSignController {
	private static Logger logger = LoggerFactory.getLogger(UserSignController.class);
	@Autowired
	private UserSignService userSignService;
	
	/**
	* **********************************************
	* @Title: signIn 
	* @Description: 签到
	* @param @param userSign
	* @param @return 
	* @return ResponseEntity<?>
	* @throws	
	* @author NingChongQing	
	* @date 2018年1月2日 下午3:41:07 
	* **********************************************
	 */
	@RequestMapping(value = "/signIn", method = RequestMethod.POST, consumes = "application/json")
	private ResponseEntity<?> signIn(@RequestBody RequestUserSign userSign) {
		try {
			if (ParameterUtils.validParams(userSign.getUserId(), userSign.getSignCode())) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
			}
			if(userSignService == null) {
				
				logger.error("签到SERVICE为空");
			}
			int result = userSignService.addUserSignInfo(userSign.getUserId(), userSign.getSignCode());
			Map<String, Integer> map = new HashMap<String, Integer>();
			map.put("signStatus", result);
			return new ResponseEntity<>(new ResponseResultModel<Map<String, Integer>>(map), HttpStatus.OK);
		} catch (Exception e) {
			logger.error("签到异常:", e);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
		}
	}
}
